package com.hexb.llk.impl
{
	import com.hexb.llk.data.Element;
	import com.hexb.llk.face.IElementCreator;
	
	public class ElementCreatorImpl implements IElementCreator
	{
		private var types:Array = [1,2,3,4,5,6,7,8,9,10] ;
		
		public function ElementCreatorImpl(){
		}
		
		public function createElements(typeNum:int, eleNum:int):Array{
			var tempTypes:Array = new Array(typeNum);
			var index:int = 0 ;
			var i:int = 0 ;
			for(i =0 ;i<typeNum ;i++){
				index = Math.random()*types.length;
				tempTypes[i] = types[index] ;
				types.splice(index,1);
			}
			
			var pair:int = eleNum / 2 ;
			var elements:Array = new Array(eleNum) ;
			
			var tempElement:Element = null;
			for(i = 0 ;i<pair ;i++){
				index = Math.random() * tempTypes.length;
				tempElement = new Element();
				tempElement.type = tempTypes[index];
				tempElement.id = i*2 ;
				elements[i*2] = tempElement ;
				
				tempElement = new Element();
				tempElement.type = tempTypes[index];
				tempElement.id = i*2+1 ;
				elements[i*2+1] = tempElement ;
			}
			
			//TODO:让随机分布更均匀
			return elements;
		}
	}
}